<?php
namespace App\Api\User;

use PhalApi\Api;
use App\Domain\User\User as UserDomain;
use App\Domain\User\UserSession as UserSessionDomain;
use PhalApi\Exception\BadRequestException;

/**
 * 用户插件
 * @author dogstar 20200331
 */
class Mine extends Api {
    public function getRules() {
        return array(
            'get' => array(
                'username' => array('name' => 'username', 'require' => true, 'min' => 1, 'max' => 50, 'desc' => '账号，账号需要唯一'),
            ),
        );
    }

    /**
     * 获取个人信息
     * @desc 获取个人信息
     * 
     * @return int res 是否更新成功
     */
    public function getByUsername() {
        // 最简单的处理方式
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: *,x-token,X-token');
        $domain = new UserDomain();
        $user = $domain->getUserByUsername($this->username, 'nickname');
        if ($user) {
            return $user;
        }
    }

    
}
